package com.ruoyi.system.util;

import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.models.*;

public class MessageUtil {

    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static void sendMsg(String tel,String params)throws Exception{
        com.aliyun.dysmsapi20170525.Client client = MessageUtil.createClient("LTAI5t6f5Xwi2owFH9GHYdZL", "LxulW0cWQI8FHpzXPyyQvkbRNtpz7k");
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(tel)
                .setSignName("徐工道金")
                .setTemplateCode("SMS_236835197")
                .setTemplateParam(params);
        // 复制代码运行请自行打印 API 的返回值
        SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
        System.out.println(sendSmsResponse);
    }
//
//    public static void main(String[] args_)  {
//        try {
//            sendMsg("15862170293","{\"code\":\"1111\"}");
//        } catch (Exception e) {
//            e.printStackTrace();
//            System.out.println("短信发送失败...");
//        }
//    }

}
